---
title: 'Data validation'
sidebarTitle: 'Data validation'
description: 'How to automatically validate your input and output with JSONSchema'
---

Nango automatically validates your integration inputs and outputs. It also offers ways to further customize data validation in code. The guide will walk you through each approach.

## Automatic validation

The validation is available during development and does not require any configuration from you:

- **CLI**: Dry Run validation errors are logged and will halt execution when using `--validation` command option


## Available schema files

When you use Nango CLI, it automatically generates two schema files in the `.nango` folder:

- `schema.ts` a TypeScript file that contains all your models
- `schema.json` a JSON Schema file that is used for automatic data validation

These files can be versioned and integrated into your own codebase, ensuring consistency and reliability across different environments.


## Validating integration outputs in your app

### Using zod

You can use zod to validate the data you receive and send to integrations.

```typescript
import * as z from 'zod';

const dataFromAPI = z.object({  
  ticketId: z.string(),
});

export default createSync({
  exec: async (nango) => {
    const response = await nango.get({ endpoint: '/tickets' });
    const isValid = dataFromAPI.parse(response.json);
    if (isValid) {
      [...]
    }
  },
});
```

### Using `schema.json` in your codebase

JSON Schema is supported in most of the main software languages. Here is a non-exhaustive list of how you can directly use this file to validate the records you receive from Nango.

<Tabs>

<Tab title="Typescript">

```ts
import { Ajv } from 'ajv';
import addFormats from 'ajv-formats';
import jsonSchema from '.nango/schema.json';

// Initiate AJV
const ajv = new Ajv({ allErrors: true, discriminator: true });
addFormats(ajv);

const modelToValidate = 'MyModelName';
const myData = {"id": "hello-word"};

// Compile the JSON schema
const validate = ajv.compile({
  ...jsonSchema,
  ...jsonSchema['definitions'][modelToValidate]
});

// Validate your data
validate(myData);
```
</Tab>


<Tab title="Golang">
```go
package main

import (
	"fmt"
	"log"
	"github.com/santhosh-tekuri/jsonschema/v5"
)

func main() {
  sch, err := jsonschema.Compile(".nango/schema.json")
  if err != nil {
    log.Fatalf("%#v", err)
  }

  myData := map[string]interface{}{
		"id": "hello-word",
	}
  if err = sch.Validate(v); err != nil {
    log.Fatalf("%#v", err)
  }
}
```
</Tab>

<Tab title="Rust">
```rust
use jsonschema::{Draft, JSONSchema};
use serde_json::json;

let data = fs::read_to_string(".nango/schema.json").expect("Unable to read file");
let schema: serde_json::Value = serde_json::from_str(&data).expect("Unable to parse");

let instance = json!("{'id': 'hello-word'}");
let compiled = JSONSchema::compile(&schema).expect("A valid schema");
let result = compiled.validate(&instance);
```
</Tab>


<Tab title="Python">
```py
import json
from jsonschema import validate

with open('.nango/schema.json') as file:
    schema = json.load(file)
    print(schema)

    validate(instance={"id": "hello-word"}, schema=schema)
```
</Tab>
</Tabs>


### Custom validation

For more advanced use cases, you can generate your own validation schemas using the available files with the tool of your choice.

<Tabs>


<Tab title="Golang">
You can use the [`go-jsonschema` golang package](https://github.com/omissis/go-jsonschema). This tool converts JSON Schema definitions into Golang structs. Note that some syntax is not supported by this package.

```bash
go-jsonschema -p main .nango/schema.json > test.go
```

</Tab>


<Tab title="Rust">

You can use the [`typify` rust package](https://github.com/oxidecomputer/typify). This tool converts JSON Schema definitions into Rust types. Note that some syntax is not supported by this package.

```bash
cargo typify .nango/schema.json
```
</Tab>
</Tabs>